/*
 * @Author: 别拿暗恋当饭吃. 13466071+lililkli@user.noreply.gitee.com
 * @Date: 2024-06-26 10:55:50
 * @LastEditors: 别拿暗恋当饭吃. 13466071+lililkli@user.noreply.gitee.com
 * @LastEditTime: 2024-06-27 15:40:36
 * @FilePath: \rabce\project\src\services\login.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// import Axios from "utils/Axios";

// export const logindata = (email: string) => {
//   return Axios.postFromData("/api/sendOutEmailCode", {
//     data: { email },
//   }).then((res) => res);
// };

import Axios from "utils/Axios";
import axios from "axios";
import { getEncryptPwd } from "utils/helper";

export type forget = {
  email: string;
  code: string;
};

export type RegisterData = {
  email: string;
  code: string;
  pwd1: string;
  pwd2: string;
};

//完善邮箱
export const improve = (data: any, email: any) => {
  return Axios({
    url: "/api/user/perfectEmail",
    method: "put",
    headers: data,
    params: email,
  });
};
//设置新密码
export const newpwd = (data: any) => {
  const pwd1 = getEncryptPwd(data.pwd1);

  data.pwd1 = pwd1 as string;
  data.pwd2 = data.pwd1;
  return Axios({
    url: "/api/user/resetUserPwd",
    method: "put",
    params: data,
  });
};

//获取验证码
export const logindata = (email: string) => {
  return Axios.postFromData("/api/user/sendOutEmailCode", {
    data: { email },
  }).then((res) => res);
};

//登录
export const logining = (data: any) => {
  const newpwd = getEncryptPwd(data.pwd);
  data.pwd = newpwd;
  return Axios.postFromData("/api/user/login", {
    data,
  }).then((res) => {
    // console.log(res);
    return res;
  });
};

//忘记密码
export const forgetpwd = (data: forget) => {
  return Axios.postFromData("/api/user/checkCode", {
    data,
  }).then((res) => {
    return res;
  });
};

//注册
export const doRegister = (data: RegisterData) => {
  console.log("我是api:", data);

  const pwd1 = getEncryptPwd(data.pwd1);

  data.pwd1 = pwd1 as string;
  data.pwd2 = data.pwd1;

  Axios.postFromData("/api/user/register", {
    data,
  }).then((res) => {
    console.log(res);
    return res;
  });
};
